home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / xexex.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  10KB  |  399 lines

  1. /***************************************************************************
  2.  
  3. Xexex
  4.  
  5. ***************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "cpuintrf.h"
  9. #include "vidhrdw/generic.h"
  10. #include "vidhrdw/konamiic.h"
  11. #include "cpu/z80/z80.h"
  12. #include "machine/eeprom.h"
  13.  
  14. int xexex_vh_start(void);
  15. void xexex_vh_stop(void);
  16. void xexex_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  17. WRITE_HANDLER( xexex_palette_w );
  18.  
  19. WRITE_HANDLER( K053157_ram_w );
  20. WRITE_HANDLER( K053157_w );
  21. READ_HANDLER( K053157_r );
  22.  
  23. static int cur_rombank;
  24. static int cur_back_select, cur_back_ctrla;
  25. static int cur_control2;
  26.  
  27. unsigned char *xexex_palette_ram;
  28.  
  29. static int init_eeprom_count;
  30.  
  31. static struct EEPROM_interface eeprom_interface =
  32. {
  33.     7,                /* address bits */
  34.     8,                /* data bits */
  35.     "011000",        /*  read command */
  36.     "011100",        /* write command */
  37.     "0100100000000",/* erase command */
  38.     "0100000000000",/* lock command */
  39.     "0100110000000" /* unlock command */
  40. };
  41.  
  42. static void nvram_handler(void *file,int read_or_write)
  43. {
  44.     if (read_or_write)
  45.         EEPROM_save(file);
  46.     else
  47.     {
  48.         EEPROM_init(&eeprom_interface);
  49.  
  50.         if (file)
  51.         {
  52.             init_eeprom_count = 0;
  53.             EEPROM_load(file);
  54.         }
  55.         else
  56.             init_eeprom_count = 10;
  57.     }
  58. }
  59.  
  60. static void gfx_init(void)
  61. {
  62.     konami_rom_deinterleave_2(REGION_GFX1);
  63.     konami_rom_deinterleave_4(REGION_GFX2);
  64. }
  65.  
  66. static void init_xexex(void)
  67. {
  68.     cur_rombank = 0;
  69.  
  70.     gfx_init();
  71. }
  72.  
  73. static READ_HANDLER( control0_r )
  74. {
  75.     return input_port_0_r(0);
  76. }
  77.  
  78. static READ_HANDLER( control1_r )
  79. {
  80.     int res;
  81.  
  82.     /* bit 0 is EEPROM data */
  83.     /* bit 1 is EEPROM ready */
  84.     /* bit 3 is service button */
  85.     res = EEPROM_read_bit() | input_port_1_r(0);
  86.  
  87.     if (init_eeprom_count)
  88.     {
  89.         init_eeprom_count--;
  90.         res &= 0xf7;
  91.     }
  92.  
  93.     return res;
  94. }
  95.  
  96. static READ_HANDLER( control2_r )
  97. {
  98.     return cur_control2;
  99. }
  100.  
  101. static WRITE_HANDLER( control2_w )
  102. {
  103.     /* bit 0  is data */
  104.     /* bit 1  is cs (active low) */
  105.     /* bit 2  is clock (active high) */
  106.     /* bit 11 is watchdog */
  107.  
  108.     EEPROM_write_bit(data & 0x01);
  109.     EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
  110.     EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
  111.     cur_control2 = data;
  112.  
  113.     /* bit 8 = enable sprite ROM reading */
  114.     K053246_set_OBJCHA_line((data & 0x0100) ? ASSERT_LINE : CLEAR_LINE);
  115. }
  116.  
  117. static int xexex_interrupt(void)
  118. {
  119.     switch (cpu_getiloops())
  120.     {
  121.         case 0:
  122.             if (K053247_is_IRQ_enabled()) return 4;    /* ??? */
  123.             break;
  124.  
  125.         case 1:
  126.             if (K053247_is_IRQ_enabled()) return 5;    /* ??? */
  127.             break;
  128.  
  129.         case 2:
  130. //            if (K053247_is_IRQ_enabled()) return 6;    /* ??? */
  131.             break;
  132.     }
  133.     return ignore_interrupt();
  134. }
  135.  
  136. static int sound_status = 0, sound_cmd = 0;
  137.  
  138. static WRITE_HANDLER( sound_cmd_w )
  139. {
  140.     logerror("Sound command : %d\n", data & 0xff);
  141.     sound_cmd = data & 0xff;
  142.     //    cpu_set_irq_line(1, 0, HOLD_LINE);
  143.     if(sound_cmd == 0xfe)
  144.       sound_status = 0x7f;
  145. }
  146.  
  147. static WRITE_HANDLER( sound_status_w )
  148. {
  149.     logerror("Sound status = %d\n", data);
  150.     sound_status = data;
  151. }
  152.  
  153. static READ_HANDLER( sound_cmd_r )
  154. {
  155.     logerror("Sound CPU read command %d\n", sound_cmd & 0xff);
  156.     cpu_set_irq_line(1, 0, CLEAR_LINE);
  157.     return sound_cmd;
  158. }
  159.  
  160. static READ_HANDLER( sound_status_r )
  161. {
  162.     return sound_status;
  163. }
  164.  
  165. static WRITE_HANDLER( sound_bankswitch_w )
  166. {
  167.     cpu_setbank(3, memory_region(REGION_CPU2) + 0x10000 + (data&7)*0x2000);
  168. }
  169.  
  170. static READ_HANDLER( back_ctrla_r )
  171. {
  172.     return cur_back_ctrla;
  173. }
  174.  
  175. static WRITE_HANDLER( back_ctrla_w )
  176. {
  177.     data &= 0xff;
  178.     if(data != cur_back_ctrla) {
  179.         logerror("Back: ctrla = %02x (%08x)\n", data, cpu_get_pc());
  180.         cur_back_ctrla = data;
  181.     }
  182. }
  183.  
  184. static READ_HANDLER( back_select_r )
  185. {
  186.     return cur_back_select;
  187. }
  188.  
  189. static WRITE_HANDLER( back_select_w )
  190. {
  191.     data &= 0xff;
  192.     if(data != cur_back_select) {
  193.         logerror("Back: select = %02x (%08x)\n", data, cpu_get_pc());
  194.         cur_back_select = data;
  195.     }
  196. }
  197.  
  198. static READ_HANDLER( backrom_r )
  199. {
  200.     if (!(cur_back_ctrla & 1))
  201.         logerror("Back: Reading rom memory with enable=0\n");
  202.     return *(memory_region(REGION_GFX3) + 2048*cur_back_select + (offset>>2));
  203. }
  204.  
  205.  
  206.  
  207. static struct MemoryReadAddress readmem[] =
  208. {
  209.     { 0x000000, 0x07ffff, MRA_ROM },
  210.     { 0x080000, 0x097fff, MRA_BANK1 },            // Main RAM
  211.     { 0x0c0000, 0x0c003f, K053157_r },
  212.     { 0x0c4000, 0x0c4001, K053246_word_r },
  213.     { 0x0c6000, 0x0c6fff, MRA_BANK4 },            // Sprites
  214.     { 0x0c800a, 0x0c800b, back_ctrla_r },
  215.     { 0x0c800e, 0x0c800f, back_select_r },
  216.     { 0x0d6014, 0x0d6015, sound_status_r },
  217.     { 0x0da000, 0x0da001, input_port_2_r },
  218.     { 0x0da002, 0x0da003, input_port_3_r },
  219.     { 0x0dc000, 0x0dc001, control0_r },
  220.     { 0x0dc002, 0x0dc003, control1_r },
  221.     { 0x0de000, 0x0de001, control2_r },
  222.     { 0x100000, 0x17ffff, MRA_ROM },
  223.     { 0x180000, 0x181fff, MRA_BANK2 },            // Graphic planes
  224.     { 0x190000, 0x191fff, MRA_BANK6 },             // Passthrough to tile roms
  225.     { 0x1a0000, 0x1a1fff, backrom_r },
  226.     { 0x1b0000, 0x1b1fff, MRA_BANK5 },
  227.     { -1 }
  228. };
  229.  
  230. static struct MemoryWriteAddress writemem[] =
  231. {
  232.     { 0x000000, 0x07ffff, MWA_ROM },
  233.     { 0x080000, 0x097fff, MWA_BANK1 },
  234.     { 0x0c0000, 0x0c003f, K053157_w },
  235.     { 0x0c2000, 0x0c2007, K053246_word_w },
  236.     { 0x0c6000, 0x0c6fff, MWA_BANK4 },
  237.     { 0x0c800a, 0x0c800b, back_ctrla_w },
  238.     { 0x0c800e, 0x0c800f, back_select_w },
  239.     { 0x0d600c, 0x0d600d, sound_cmd_w },
  240.     { 0x0de000, 0x0de001, control2_w },
  241.     { 0x100000, 0x17ffff, MWA_ROM },
  242.     { 0x180000, 0x181fff, K053157_ram_w },
  243.     { 0x1b0000, 0x1b1fff, xexex_palette_w, &xexex_palette_ram },
  244.     { -1 }
  245. };
  246.  
  247. #if 0
  248. static struct MemoryReadAddress sound_readmem[] =
  249. {
  250.     { 0x0000, 0x7fff, MRA_ROM },
  251.     { 0x8000, 0xbfff, MRA_BANK3 },
  252.     { 0xc000, 0xdf7f, MRA_RAM },
  253.     { 0xe000, 0xe22f, MRA_RAM },
  254.     { 0xec01, 0xec01, YM2151_status_port_0_r },
  255.     { 0xf002, 0xf002, sound_cmd_r },
  256.     { -1 }
  257. };
  258.  
  259. static struct MemoryWriteAddress sound_writemem[] =
  260. {
  261.     { 0x0000, 0xbfff, MWA_ROM },
  262.     { 0xc000, 0xdf7f, MWA_RAM },
  263.     { 0xe000, 0xe22f, MWA_RAM },
  264.     { 0xec00, 0xec00, YM2151_register_port_0_w },
  265.     { 0xec01, 0xec01, YM2151_data_port_0_w },
  266.     { 0xf000, 0xf000, sound_status_w },
  267.     { 0xf800, 0xf800, sound_bankswitch_w },
  268.     { -1 }
  269. };
  270. #endif
  271.  
  272.  
  273. INPUT_PORTS_START( xexex )
  274.     PORT_START
  275.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  276.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  277.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 )
  278.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN4 )
  279.     PORT_BIT( 0xcc, IP_ACTIVE_LOW, IPT_UNKNOWN )
  280.  
  281.     PORT_START
  282.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )    // EEPROM data
  283.     PORT_BIT( 0x02, IP_ACTIVE_LOW,  IPT_UNUSED )    // EEPROM ready (always 1)
  284.     PORT_BITX(0x08, IP_ACTIVE_LOW, IPT_SERVICE, DEF_STR( Service_Mode ), KEYCODE_F2, IP_JOY_NONE )
  285.     PORT_BIT( 0xf4, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  286.  
  287.     PORT_START
  288.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  289.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  290.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  291.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  292.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  293.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  294.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  295.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
  296.  
  297.     PORT_START
  298.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  299.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  300.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  301.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  302.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  303.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  304.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  305.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
  306.  
  307. INPUT_PORTS_END
  308.  
  309. static struct GfxLayout char_layout =
  310. {
  311.     8, 8,
  312.     0x200000*8/(8*8*4),
  313.     4,
  314.     { 0, 1, 2, 3 },
  315.     { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  316.     { 0*8*4, 1*8*4, 2*8*4, 3*8*4, 4*8*4, 5*8*4, 6*8*4, 7*8*4 },
  317.     8*8*4,
  318. };
  319.  
  320. static struct GfxDecodeInfo gfxdecodeinfo[] =
  321. {
  322.     { REGION_GFX1, 0x000000, &char_layout, 0, 128 },
  323.     { -1 }
  324. };
  325.  
  326. static struct MachineDriver machine_driver_xexex =
  327. {
  328.     {
  329.         {
  330.             CPU_M68000,
  331.             16000000,    /* 16 MHz ? (xtal is 32MHz) */
  332.             readmem, writemem, 0, 0,
  333.             xexex_interrupt, 3    /* ??? */
  334.         },
  335. #if 0
  336.         {
  337.             CPU_Z80,
  338.             2000000,    /* 2 MHz ? (xtal is 32MHz/19.432Mhz) */
  339.             sound_readmem, sound_writemem, 0, 0,
  340.             ignore_interrupt, 1
  341.         },
  342. #endif
  343.     },
  344.     60, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  345.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  346.     0,
  347.  
  348.     /* video hardware */
  349.     64*8, 32*8,
  350.     { 0*8, 64*8-1, 0*8, 32*8-1 },
  351.     gfxdecodeinfo,
  352.     2048, 2048,
  353.     0,
  354.  
  355.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  356.     0,
  357.     xexex_vh_start,
  358.     xexex_vh_stop,
  359.     xexex_vh_screenrefresh,
  360.  
  361.     /* sound hardware */
  362.     0,0,0,0,
  363.     {
  364.         {0}
  365.     },
  366.  
  367.     nvram_handler
  368. };
  369.  
  370.  
  371. ROM_START( xexex )
  372.     ROM_REGION( 0x180000, REGION_CPU1 )
  373.     ROM_LOAD_EVEN( "xex_a01.rom", 0x000000,  0x40000, 0x3ebcb066 )
  374.     ROM_LOAD_ODD ( "xex_a02.rom", 0x000000,  0x40000, 0x36ea7a48 )
  375.     ROM_LOAD_EVEN( "xex_b03.rom", 0x100000,  0x40000, 0x97833086 )
  376.     ROM_LOAD_ODD ( "xex_b04.rom", 0x100000,  0x40000, 0x26ec5dc8 )
  377.  
  378.     ROM_REGION( 0x30000, REGION_CPU2 )
  379.     ROM_LOAD( "xex_a05.rom", 0x000000, 0x020000, 0x0e33d6ec )
  380.     ROM_RELOAD(              0x010000, 0x020000 )
  381.  
  382.     ROM_REGION( 0x200000, REGION_GFX1 )
  383.     ROM_LOAD( "xex_b14.rom", 0x000000, 0x100000, 0x02a44bfa )
  384.     ROM_LOAD( "xex_b13.rom", 0x100000, 0x100000, 0x633c8eb5 )
  385.  
  386.     ROM_REGION( 0x400000, REGION_GFX2 )
  387.     ROM_LOAD( "xex_b12.rom", 0x000000, 0x100000, 0x08d611b0 )
  388.     ROM_LOAD( "xex_b11.rom", 0x100000, 0x100000, 0xa26f7507 )
  389.     ROM_LOAD( "xex_b10.rom", 0x200000, 0x100000, 0xee31db8d )
  390.     ROM_LOAD( "xex_b09.rom", 0x300000, 0x100000, 0x88f072ef )
  391.  
  392.     ROM_REGION( 0x80000, REGION_GFX3 )
  393.     ROM_LOAD( "xex_b08.rom", 0x000000, 0x080000, 0xca816b7b )
  394. ROM_END
  395.  
  396.  
  397.  
  398. GAME( 1991, xexex, 0, xexex, xexex, xexex, ORIENTATION_FLIP_Y, "Konami", "Xexex" )
  399.